<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\StatisticPhoneRecord;

class StatisticDataController extends Controller
{
    protected $record;

    public function __construct(StatisticPhoneRecord $record)
    {
        $this->record = $record;
    }

    /**
     * @api {get} /api/customVisits?limit=5&page=2&time_type=1 客服回访统计列表
     * @apiGroup Statistic
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} time_type  时间类型(时间类型 1、前一天 2、近一周 3、近一个月) 必传
     * @apiParam {int} limit  每页数量 非必传
     * @apiParam {int} page  第几页 非必传
     *
     * @apiSuccess {int} any_id 客服id
     * @apiSuccess {int} type 类型值
     * @apiSuccess {int} call_times 客服回访次数
     * @apiSuccess {int} visit_number 客服回访人数
     * @apiSuccess {int} connect_number  客服回访接通人数
     * @apiSuccess {int} login_number 客服回访登录人数
     * @apiSuccess {int} charge_number 客服回访充值人数
     * @apiSuccess {int} member_number 客服分配会员数
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *       {
     *           "data": [
     *               {
     *                   "any_id": 1,
     *                   "type": 0,
     *                   "call_times": 9,
     *                   "visit_number": 8,
     *                   "connect_number": 8,
     *                   "login_number": 0,
     *                   "charge_number": 0,
     *                   "member_number": 19
     *               },
     *               {
     *                   "any_id": 2,
     *                   "type": 0,
     *                   "call_times": 8,
     *                   "visit_number": 6,
     *                   "connect_number": 6,
     *                   "login_number": 0,
     *                   "charge_number": 0,
     *                   "member_number": 15
     *               },
     *               {
     *                   "any_id": 3,
     *                   "type": 0,
     *                   "call_times": 5,
     *                   "visit_number": 5,
     *                   "connect_number": 4,
     *                   "login_number": 0,
     *                   "charge_number": 0,
     *                   "member_number": 6
     *               },
     *           ],
     *           "meta": {
     *               "pagination": {
     *                   "total": 2,
     *                   "count": 2,
     *                   "per_page": 5,
     *                   "current_page": 1,
     *                   "total_pages": 1,
     *                   "links": null
     *               }
     *           }
     *       }
     */
    public function customVisits(Request $request)
    {
        $params = $request->only(['time_type', 'limit', 'page']);
        $data = $this->record->getCustomVisit($params);

        if (empty($data)) {
            return $this->response->array(['data' => []]);
        }

        return $this->response->array($data);
    }

    /**
     * @api {get} /api/sectionVisits?time_type=:time_type  部门回访统计
     * @apiGroup Statistic
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} time_type  时间类型(时间类型 1、近3天 2、近7天 3、近一个月)
     * @apiParam {int} value_type 统计类型(统计类型 1、回访次数 2、回访人数 3、回访登录人数 4、回访充值人数)
     *
     * @apiSuccess {int} any_id 部门id
     * @apiSuccess {int} type 类型
     * @apiSuccess {string} name 部门名
     * @apiSuccess {int} value 部门回访次数,部门回访人数,回访接通人数,回访登录人数，回访充值人数
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *           {
     *               "data": [
     *                  {
     *                     "any_id": 3,
     *                     "type": 2,
     *                     "name": "运维",
     *                     "value": 7,
     *                  }
     *             ]
     *         }
     *
     **/
    public function sectionVisits(Request $request)
    {
        $params = $request->only(['time_type', 'value_type']);
        $data = $this->record->getSectionVisit($params);

        return $this->response->array(['data' => $data]);
    }

    /**
     * @api {get} /api/personalGrade?time_type=1&type=1 绩效计算
     * @apiGroup Statistic
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} time_type 时间类型 1、本周 2、本月 3、全部
     * @apiParam {int} type  1、个人绩效 2、整体绩效
     *
     * @apiSuccess {int} task_count 分派给我的任务数量
     * @apiSuccess {int} finish_count 已完成数量
     * @apiSuccess {int} over_number  逾期数量
     * @apiSuccess {int} over_not_number 逾期未完成数量
     * @apiSuccess {int} over_yes_number 逾期完成数量
     * @apiSuccess {decimal} finish_rate 任务整体完成度 50表示50%
     *
     * @apiSuccess {int} call_times 回访次数
     * @apiSuccess {int} visit_number  回访人数
     * @apiSuccess {int} login_number 登录人数
     * @apiSuccess {int} connect_rate 接通率
     * @apiSuccess {decimal} login_rate 登录率 50表示50%
     *
     * @apiSuccess {int} charge_number 充值人数
     * @apiSuccess {int} sms_count  短信次数
     * @apiSuccess {int} sms_number 短信人数
     * @apiSuccess {decimal} charge_rate 充值率 50表示50%
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *           {
     *               "data": {
     *                  "task": {
     *                      "task_count": 4,
     *                      "finish_count": 2,
     *                      "over_number": 0,
     *                      "over_not_number": 0,
     *                      "over_yes_number": 0,
     *                      "finish_rate": 50
     *                  },
     *                  "phone": {
     *                      "call_times": "9",
     *                      "visit_number": "8",
     *                      "login_number": "3",
     *                      "connect_rate": 100,
     *                      "login_rate": 37.5
     *                  },
     *                  "sms": {
     *                      "charge_number": "0",
     *                      "sms_count": "4",
     *                      "sms_number": "6",
     *                      "charge_rate": 50
     *                   }
     *             }
     *         }
     *
     **/
    public function personalGrade(Request $request)
    {
        $params = $request->only(['time_type', 'type']);
        $data = $this->record->getGrade($params);

        return $this->response->array(['data' => $data]);
    }

    /**
     * @api {get} /api/personalRecentTasks  当前用户近七天任务
     * @apiGroup Statistic
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     *
     * @apiSuccess {int} 20 第1天打电话次数 (20表示20号)
     * @apiSuccess {int} 21 第2天打电话次数
     * @apiSuccess {int} 22 第3天打电话次数
     * @apiSuccess {int} 23 第4天打电话次数
     * @apiSuccess {int} 24 第5天打电话次数
     * @apiSuccess {int} 25 第6天打电话次数
     * @apiSuccess {int} 26 第7天打电话次数
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *           {
     *               "data":{
     *                     "20": 1,
     *                     "21": 0,
     *                     "22": 3,
     *                     "23": 1,
     *                     "24": 0,
     *                     "25": 1,
     *                     "26": 0
     *                  }
     *         }
     *
     **/
    public function personalRecentTasks()
    {
        $data = $this->record->getRecentTasks();

        return $this->response->array(['data' => $data]);
    }
}
